<?php
ini_set("display_errors", "On");
error_reporting(E_ALL);

// 引入数据库连接文件
require_once '../../../../sql/connection.php';

$connCouID = $_POST['connCouID'];
$connTeacherID = $_POST['connTeacherID'];

$now = date('Y-m-d H:i:s', time());

$querySql = "select id from `teacher-course` where c_ID = '$connCouID' and t_ID = '$connTeacherID';";
$temp = mysqli_query($GLOBALS['conn'], $querySql);
if (mysqli_num_rows(mysqli_query($GLOBALS['conn'], $querySql)))
{
	$addSql = "UPDATE `teacher-course` SET is_delete = 0 where c_ID = '$connCouID' and t_ID = '$connTeacherID';";
	
}
else
{
	$addSql = "INSERT INTO `teacher-course` (create_time, update_time, c_ID, t_ID,is_delete) VALUES ('$now', '$now', '$connCouID', '$connTeacherID',0)";
}
if (mysqli_query($GLOBALS['conn'], $addSql)) {
	echo "
            <script>
                alert('关联成功！');
                window.location.href=document.referrer;
            </script>
        ";
} else {
	echo "
            <script>
                alert('关联失败！');
                history.back();
            </script>
        ";
}
